﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:i="http://www.codeplex.com/CompositeExtensions/TestSuite/Interface"
    xmlns:v="clr-namespace:Jbe.TestSuite.Infrastructure.Shell.Presentation">

    <Style x:Key="NewCommandStyle" TargetType="MenuItem">
        <Setter Property="Header" Value="{Binding Description}"/>
        <!-- INFO: The CommandParameter has to be set first! Otherwise the CanExecute method doesn't get this value. -->
        <Setter Property="CommandParameter" Value="{Binding}"/>
        <Setter Property="Command" Value="{x:Static i:DocumentCommands.New}"/>
    </Style>

    <Style x:Key="ViewTabStyle" TargetType="TabItem">
        <Setter Property="Header" Value="{Binding Content.DataContext}"/>
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding HeaderIcon}" Width="16" Height="16" Margin="0,0,2,0" 
                                           Visibility="{Binding Source, Converter={x:Static v:NullToCollapsedConverter.Default}, 
                                                RelativeSource={RelativeSource Self}}"/>
                        <TextBlock Text="{Binding HeaderInfo}" VerticalAlignment="Center"/>
                    </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="DocumentTabStyle" TargetType="TabItem" BasedOn="{StaticResource ViewTabStyle}">
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Source="{Binding HeaderIcon}" Width="16" Height="16" Margin="0,0,2,0" 
                                           Visibility="{Binding Source, Converter={x:Static v:NullToCollapsedConverter.Default}, 
                                                RelativeSource={RelativeSource Self}}"/>
                        <TextBlock Text="{Binding HeaderInfo}" VerticalAlignment="Center"/>
                        <Button Command="{x:Static i:DocumentCommands.Close}" Content="{DynamicResource CloseSmallImage}"
                                            Visibility="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}},
                                                Converter={x:Static v:BoolToCollapsedConverter.Default}, ConverterParameter=Inverse}"
                                            Width="16" Height="16" BorderThickness="0"
                                            MinWidth="0" MinHeight="0" Padding="0" Margin="7,0,0,0">
                            <Button.Template>
                                <ControlTemplate TargetType="{x:Type Button}">
                                    <ContentPresenter Margin="{TemplateBinding Control.Padding}" 
                                                                  HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                                  VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                                                  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
                                                                  ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                                                  RecognizesAccessKey="True"
                                                                  Content="{TemplateBinding ContentControl.Content}"/>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>